#pragma once

#include <map>
#include <string>

//#include "SDL.h"
#include "IInput.h"
/**
 * Definitions
 */
#define MAX_KEYS 333
#define MAX_BUTTONS 4
#define MAX_JOYSTICKBUTTONS 10


/**
=============================
A key representation
=============================
*/
typedef struct {
    bool isDown;
    bool Released;

    float   TimeStamp;
    float   NextTime;
    float   TotalTime;
} Key;

#include "Irrlicht.h"

/**
=================================
Irrlicht Implementation
=================================
*/
class IrrInput : public IInput, public irr::IEventReceiver
{
public:
    IrrInput(void);
    /** Initialize the input system */
    int Init( const InputSettings &settings  );
    /** Poll for events */
	void Update(float dt);
    /** Shutdown */
	void Shutdown();

    /** Irrlicht interface */
    virtual bool OnEvent(irr::SEvent evt );
    /*----------------------------
        Handle Joystick Input
    -----------------------------*/

    /** Test to see if there is a joystick availible, return the count */
    int CheckJoystick();
    /** Enable the joystick module */
    void EnableJoystick();

    /** Check the x-axis */
    int GetJoystickX();
    /** Check the y-axis */
    int GetJoystickY();
    /** Test to see if a button is down */
    int IsJoystickButtonDown(int button, bool stamp=false);

    /*----------------------------
        Handle the mouse 
    -----------------------------*/

    /** Get the mouse x-pos */
    int GetMouseX();
    /** Get the mouse y-pos */
	int GetMouseY();

    /** Get the change in x */
    int GetDeltaMX();
    /** Get the change in y */
    int GetDeltaMY();
    /** Test to see if a mouse button is down */
    bool IsButtonDown( int button, bool stamp=false );
    /** Test to see if a button is released */
    bool ButtonReleased( int button );

    /*---------------------------------
        Handle keyboard 
    ----------------------------------*/

    /** Test to see if a key is down */
    bool IsKeyDown( int key, bool stamp=false );
    /** Test to see if a key is released */
    bool KeyReleased( int key );

private:
    /** Handle a Mouse Event */
    void HandleMouseEvent();
    /** Handle a Key Event */
    void HandleKeyEvent( float dt );

    /** Process the events to the Listeners */
    void ProcessKeyEvent( KeyEvent* e, bool keyDown );
    /** Process a mouse event to the listeners */
    void ProcessMouseEvent( MouseEvent* e );

    irr::SEvent m_IrrEvent;

    bool    m_register;
         // keyboard buttons
    Key  key[MAX_KEYS];
    // joystick buttons
    Key  joyStickButtons[MAX_JOYSTICKBUTTONS];
    // mouse buttons
    bool button[MAX_BUTTONS];

public:
    virtual ~IrrInput(void);
};
